package ${apiPackage}

import org.springframework.stereotype.Service
import ${servicePackage}.${serviceName}
import ${entityPackage}.${entityName}
import ${modelPackage}.${modelName}

/**
* ${tableComment} API
* @author ${author}
* @since ${date}
*/
@Service
open class ${apiName}(
    private val ${serviceName?uncap_first}: ${serviceName}
){

    /**
     * 插入新数据
     * @author ${author}
     * @since ${date}
     * @param model:
    */
    fun insert(model: ${modelName}){
        val entity = ${entityName}.convert(model,${entityName}())
        <#if enableMyBatisPlus>
        ${serviceName?uncap_first}.save(entity)
        <#else>
        ${serviceName?uncap_first}.insert(entity)
        </#if>
    }

<#if primaryColumn?? && (primaryColumn?size == 1)>
    /**
     * 根据ID删除记录
     * @author ${author}
     * @since ${date}
     * @param id:
    */
    fun deleteById(id: ${primaryColumn[0].javaType}){
    <#if enableMyBatisPlus>
        ${serviceName?uncap_first}.removeById(id)
    <#else>
        ${serviceName?uncap_first}.deleteById(id)
    </#if>
    }

    /**
     * 根据ID选择性更新
     * @author ${author}
     * @since ${date}
     * @param model:
    */
    fun updateSelectiveById(model: ${modelName}){
        val entity = ${entityName}.convert(model,${entityName}())
        ${serviceName?uncap_first}.updateSelectiveById(entity!!)
    }

    /**
     * 根据ID查询记录
     * @author ${author}
     * @since ${date}
     * @param id:
     * @return ${modelPackage}.${modelName}
    */
    fun selectById(id: ${primaryColumn[0].javaType}): ${modelName}?{
    <#if enableMyBatisPlus>
        val entity = ${serviceName?uncap_first}.getById(id)
    <#else>
        val entity = ${serviceName?uncap_first}.selectById(id)
    </#if>
        return ${entityName}.convert(entity,${modelName}());
    }

</#if>

}

